package com.ymatou.iapi.csim.testcase;

import java.text.SimpleDateFormat;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.SendMessageCSBean;
import com.ymatou.iapi.csim.parameter.ValidateWorkOrderBean;
import com.ymatou.iapi.csim.service.ValidateWorkOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
/**
*验证会话是否属于用户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ValidateWorkOrder{
	private static ValidateWorkOrderBean bean;
	private static ValidateWorkOrderCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static Integer userId=Integer.parseInt(EnvSetup.getData("userId_IM").toString());
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("验证会话是否属于用户");
	}

	@Before
	public void caseUp() {
		bean=new ValidateWorkOrderBean();
		call=new ValidateWorkOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ValidateWorkOrder_1() {
		Logger.start(true,"验证会话是否属于用户,验证属于");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			service.setSendMessageCSCall(sendMessageCSBean);
			
			bean.setSessionNumber(cssession.getSessionNumber());
			bean.setUserId(cssession.getUserId());
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("0", call.getResult().get("Result").toString(), "验证Result=0(0：匹配 -1：不匹配 -2：未找到会话)");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ValidateWorkOrder_2() {
		Logger.start(true,"验证会话是否属于用户，验证不属于");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			service.setSendMessageCSCall(sendMessageCSBean);
			
			bean.setSessionNumber(cssession.getSessionNumber());
			bean.setUserId(cssession.getUserId()+1);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("-1", call.getResult().get("Result").toString(), "验证Result=0(0：匹配 -1：不匹配 -2：未找到会话)");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ValidateWorkOrder_3() {
		Logger.start(true,"验证会话是否属于用户，验证会话不存在");
		try {
			//客服上线
			service.getOnlineCS(csId);
			//打开会话
			ymt_cssession cssession=service.getOpenSession(csId,userId);
			//发消息
			SendMessageCSBean sendMessageCSBean=service.setSendMessageCSBean();
			sendMessageCSBean.setSessionId(cssession.getId());
			sendMessageCSBean.setCsId(csId);
			sendMessageCSBean.setUserId(userId);
			service.setSendMessageCSCall(sendMessageCSBean);
			
			bean.setSessionNumber(cssession.getSessionNumber()+1);
			bean.setUserId(cssession.getUserId());
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("0", call.getResult().get("ErrorCode").toString(), "验证errorCode");
			Logger.verifyEquals(true, call.getResult().get("Success"), "验证Success");
			Logger.verifyEquals("-2", call.getResult().get("Result").toString(), "验证Result=0(0：匹配 -1：不匹配 -2：未找到会话)");
			Logger.verifyEquals("200", call.getStatus(), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}